home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
ada
/
gwuada_6.zip
/
MENUS.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-09-06
|
15KB
|
604 lines
/*
GWAda Development Environment for 386/486 PCs
Copyright (C) 1993, Arthur Vargas Lopes & Michael Bliss Feldman
vlopes@vortex.ufrgs.br mfeldman@seas.gwu.edu
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* Menus.c */
#include <externs.h>
/************************************************************************/
/*** Inicializa o Mouse no Video ***/
/* */
void AVL_MOUSE_INIT()
{
union REGS inreg, outreg;
return;
inreg.x.ax = 0;
int86(0x33, &inreg, &outreg);
inreg.x.ax = 1;
int86(0x33, &inreg, &outreg);
}
void AVL_MOUSE_ON()
{
union REGS inreg, outreg;
return;
inreg.x.ax = 1;
int86(0x33, &inreg, &outreg);
}
void AVL_MOUSE_OFF()
{
union REGS inreg, outreg;
return;
inreg.x.ax = 2;
int86(0x33, &inreg, &outreg);
}
void AVL_MOUSE_SET(int x, int y)
{
union REGS inreg, outreg;
return;
inreg.x.ax = 4;
inreg.x.cx = x;
inreg.x.dx = y;
int86(0x33, &inreg, &outreg);
}
/************************************************************************/
/*** Fornece o Status do Mouse - Posicao, Botao Precionado. ***/
/** Botoes: 0 - esquerda **/
/* 1 - direita Obs.: Definir estrutura de volta */
/* 2 - meio fora do programa. xmouse */
/* ymouse */
/* Retorna: 1 - se botao pressionado */
/* 0 - caso contrario ou se nro. do botao for invalido */
/* */
AVL_MOUSE AVL_MOUSE_STATUS()
{
union REGS inreg, outreg;
static AVL_MOUSE m;
short i;
m.status = 0;
return m;
inreg.x.ax = 3;
inreg.x.bx = 0;
int86(0x33, &inreg, &outreg);
m.x = outreg.x.dx;
m.y = outreg.x.cx;
m.x = m.x / 8 + 1;
m.y = m.y / 8 + 1;
m.status = outreg.x.bx;
return(m);
}
int AVL_MOUSE_SELECT(int x1, int y1, int x2, int y2, int *row)
{
AVL_MOUSE m;
m = AVL_MOUSE_STATUS();
return 0;
if (m.x >= x1 && m.x <= x2 && m.y >= y1 && m.y <= y2 && m.status == 1) {
*row = m.x - x1;
avl_cur_smenu[avl_cur_menu] = *row;
AVL_SHOW_SMENU();
return 1;
}
return 0;
}
int AVL_MOUSE_SELECT2(int *item)
{
AVL_MOUSE m;
short k, y1, y2;
m = AVL_MOUSE_STATUS();
return 0;
if (m.x == 2 && m.status == 1)
for(k = 0; k < AVL_MENU_ITEMS; ++k) {
y1 = avl_menu[k].c + 1;
y2 = strlen(avl_menu[k].tit) + y1 - 1;
if (m.y >= y1 && m.y <= y2 && k != avl_cur_menu) {
*item = avl_menu[k].tit[0];
avl_cur_menu = k;
AVL_SHOW_MENU();
return 1;
}
}
*item = avl_menu[avl_cur_menu].tit[0];
return (m.status == 1) ? 1 : 0;
}
void AVL_SHOW_SMENU()
{
int i, j, rows = 0, cols = 0;
short co;
for(i = 0; *(avl_smenu[avl_cur_menu].s[i].sm) != '\0'; ++i) {
_settextposition(avl_smenu[avl_cur_menu].r+i,1);
if (avl_cur_smenu[avl_cur_menu] == i)
co = _settextcolor(avl_men_ready);
else
co = _settextcolor(avl_men_letter);
_outmem(avl_smenu[avl_cur_menu].s[i].sm,1);
if (avl_cur_smenu[avl_cur_menu] != i)
_settextcolor(avl_men_word);
_outtext(avl_smenu[avl_cur_menu].s[i].sm + 1);
}
}
int AVL_GET_SMENU_OPT()
{
int ch, i, j;
short att, c1;
int rows, cols;
AVL_WIN_PTR w = NULL;
AVL_SHOW_MENU();
AVL_COMP_SMENU(&rows,&cols);
AVL_MOUSE_ON();
AVL_MOUSE_SET(2,2);
avl_no_up_corner = 1;
c1 = avl_menu[avl_cur_menu].c - 1;
ch = 78 - (c1 + cols);
if (ch < 0) c1 += ch;
if (!(rows == 0 && cols == 0))
w = AVL_MAKE_WINDOW("",3,c1,rows+4,c1+cols+1,avl_men_bk_color,avl_wnd_color);
_settextcursor(0x2000);
while ( 1 ) {
if (w != NULL)
AVL_SHOW_SMENU();
_settextposition(1,1);
again:
if (!kbhit()) {
if (AVL_MOUSE_SELECT(4,c1+1,rows+3,c1+cols,&i)) {
AVL_DEL_WINDOW(w);
if (avl_smenu[avl_cur_menu].s[i].ret_edit) {
ch = 0;
AVL_DEL_WINDOW(avl_env_win);
AVL_RESTORE_ENV();
}
else
ch = *(avl_smenu[avl_cur_menu].s[i].sm);
avl_smenu[avl_cur_menu].s[i].proc();
/* if ((avl_cur_menu == 0) && (avl_cur_smenu[avl_cur_menu] == 3))
AVL_BORDER(" GWAda Development Environment ",1,1,3,80,avl_men_bk_color,avl_wnd_color);
*/
avl_no_up_corner = 0;
AVL_MOUSE_OFF();
return ch;
}
goto again;
}
ch = getch();
ch = toupper(ch);
if (ch >= 'A' && ch <= 'Z') {
if (w == NULL) {
AVL_ERROR("Invalid action");
continue;
}
for (i = 0; i < rows; ++i)
if (*(avl_smenu[avl_cur_menu].s[i].sm) == ch) {
avl_cur_smenu[avl_cur_menu] = i;
AVL_DEL_WINDOW(w);
if (avl_smenu[avl_cur_menu].s[i].ret_edit) {
ch = 0;
AVL_DEL_WINDOW(avl_env_win);
AVL_RESTORE_ENV();
}
avl_smenu[avl_cur_menu].s[i].proc();
/* if ((avl_cur_menu == 0) && (avl_cur_smenu[avl_cur_menu] == 3))
AVL_BORDER(" GWAda Development Environment ",1,1,3,80,avl_men_bk_color,avl_wnd_color);
*/
avl_no_up_corner = 0;
AVL_MOUSE_OFF();
return ch;
}
continue;
}
else {
switch( ch ) {
case 27 : /* Abort Menu */
AVL_DEL_WINDOW(w);
avl_no_up_corner = 0;
AVL_MOUSE_OFF();
return 1;
case 13 : /* Engage current selection */
AVL_DEL_WINDOW(w);
ch = *(avl_smenu[avl_cur_menu].s[avl_cur_smenu[avl_cur_menu]].sm);
if (avl_smenu[avl_cur_menu].s[avl_cur_smenu[avl_cur_menu]].ret_edit) {
ch = 0;
AVL_DEL_WINDOW(avl_env_win);
AVL_RESTORE_ENV();
}
avl_smenu[avl_cur_menu].s[avl_cur_smenu[avl_cur_menu]].proc();
/* if ((avl_cur_menu == 0) && (avl_cur_smenu[avl_cur_menu] == 3))
AVL_BORDER(" GWAda Development Environment ",1,1,3,80,avl_men_bk_color,avl_wnd_color);
*/
avl_no_up_corner = 0;
AVL_MOUSE_OFF();
return ch;
case 0 :
case 0XE0: {
ch = getch();
switch(ch) {
case 72 : /* Up */
if (avl_cur_smenu[avl_cur_menu] > 0)
--avl_cur_smenu[avl_cur_menu];
else
avl_cur_smenu[avl_cur_menu] = rows - 1;
break;
case 80 : /* Down */
if (avl_cur_smenu[avl_cur_menu] < (rows - 1))
++avl_cur_smenu[avl_cur_menu];
else
avl_cur_smenu[avl_cur_menu] = 0;
break;
case 75 : /* Left */
if (avl_cur_menu > 0)
--avl_cur_menu;
else
avl_cur_menu = 8;
AVL_DEL_WINDOW(w);
w = NULL;
AVL_SHOW_MENU();
AVL_COMP_SMENU(&rows,&cols);
c1 = avl_menu[avl_cur_menu].c - 1;
ch = 78 - (c1 + cols);
if (ch < 0) c1 += ch;
if (!(rows == 0 && cols == 0))
w = AVL_MAKE_WINDOW("",3,c1,rows+4,c1+cols+1,avl_men_bk_color,avl_wnd_color);
_settextcursor(0x2000);
break;
case 77 : /* Right */
if (avl_cur_menu < 8)
++avl_cur_menu;
else
avl_cur_menu = 0;
AVL_DEL_WINDOW(w);
w = NULL;
AVL_SHOW_MENU();
AVL_COMP_SMENU(&rows,&cols);
c1 = avl_menu[avl_cur_menu].c - 1;
ch = 78 - (c1 + cols);
if (ch < 0) c1 += ch;
if (!(rows == 0 && cols == 0))
w = AVL_MAKE_WINDOW("",3,c1,rows+4,c1+cols+1,avl_men_bk_color,avl_wnd_color);
else
w = NULL;
_settextcursor(0x2000);
break;